//
//  WelcomeViewController.m
//  微博
//
//  Created by 沈艳男 on 15/12/1.
//  Copyright © 2015年 沈艳男. All rights reserved.
//

#import "WelcomeViewController.h"

@interface WelcomeViewController ()
@property (nonatomic, strong) UIImageView *backImageView;
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *welcomeLabel;
@end

@implementation WelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupUI
{
    // 添加控件
    [self.view addSubview:self.backImageView];
    [self.view addSubview:self.iconView];
    [self.view addSubview:self.welcomeLabel];
    
    // 自动布局
    self.backImageView.translatesAutoresizingMaskIntoConstraints = NO;
    self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
    self.welcomeLabel.translatesAutoresizingMaskIntoConstraints = NO;
    
    NSLayoutConstraint *backImageViewConstraint1 = [NSLayoutConstraint constraintWithItem:self.backImageView attribute:(NSLayoutAttributeTop) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:(NSLayoutAttributeTop) multiplier:1 constant:0];
    NSLayoutConstraint *backImageViewConstraint2 = [NSLayoutConstraint constraintWithItem:self.backImageView attribute:(NSLayoutAttributeBottom) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:(NSLayoutAttributeBottom) multiplier:1 constant:0];
    NSLayoutConstraint *backImageViewConstraint3 = [NSLayoutConstraint constraintWithItem:self.backImageView attribute:(NSLayoutAttributeRight) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:(NSLayoutAttributeRight) multiplier:1 constant:0];
    NSLayoutConstraint *backImageViewConstraint4 = [NSLayoutConstraint constraintWithItem:self.backImageView attribute:(NSLayoutAttributeLeft) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:(NSLayoutAttributeLeft) multiplier:1 constant:0];
    
    NSLayoutConstraint *iconViewConstraint1 = [NSLayoutConstraint constraintWithItem:self.iconView attribute:(NSLayoutAttributeCenterX) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:(NSLayoutAttributeCenterX) multiplier:1 constant:0];
    NSLayoutConstraint *iconViewConstraint2 = [NSLayoutConstraint constraintWithItem:self.iconView attribute:(NSLayoutAttributeBottom) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:(NSLayoutAttributeBottom) multiplier:1 constant:-200];
    
    NSLayoutConstraint *welcomeConstraint1 = [NSLayoutConstraint constraintWithItem:self.welcomeLabel attribute:(NSLayoutAttributeCenterX) relatedBy:(NSLayoutRelationEqual) toItem:self.iconView attribute:(NSLayoutAttributeCenterX) multiplier:1 constant:0];
    NSLayoutConstraint *welcomeConstraint2 = [NSLayoutConstraint constraintWithItem:self.welcomeLabel attribute:(NSLayoutAttributeTop) relatedBy:(NSLayoutRelationEqual) toItem:self.iconView attribute:(NSLayoutAttributeBottom) multiplier:1 constant:16];
    
    
    [self.view addConstraint:backImageViewConstraint1];
    [self.view addConstraint:backImageViewConstraint2];
    [self.view addConstraint:backImageViewConstraint3];
    [self.view addConstraint:backImageViewConstraint4];
    [self.view addConstraint:iconViewConstraint1];
    [self.view addConstraint:iconViewConstraint2];
    [self.view addConstraint:welcomeConstraint1];
    [self.view addConstraint:welcomeConstraint2];
}

- (UIImageView *)backImageView
{
    if (!_backImageView) {
        UIImageView *backImageView = [[UIImageView alloc] init];
        backImageView.image = [UIImage imageNamed:@"ad_background"];
        _backImageView = backImageView;
    }
    return _backImageView;
}

- (UIImageView *)iconView
{
    if (!_iconView) {
        UIImageView *iconView = [[UIImageView alloc] init];
        iconView.image = [UIImage imageNamed:@"avatar_default_big"];
        _iconView = iconView;
    }
    return _iconView;
}

- (UILabel *)welcomeLabel
{
    if (!_welcomeLabel) {
        UILabel *welcomeLabel = [[UILabel alloc] init];
        welcomeLabel.text = @"欢迎归来";
        _welcomeLabel = welcomeLabel;
    }
    return _welcomeLabel;
}
@end
